<template>
  <div class="details-container">
    <h3 class="title">{{ news.title }}</h3>
    <p class="subtitle">
      <span>发表时间：{{ news.add_time | dateFormat }}</span>
      <span>点击{{ news.hits }}次</span>
    </p>
    <hr>
    <div class="content" v-html="news.content">
    </div>
    <!-- <comments :newsId="news._id"></comments> -->
    <comments></comments>
  </div>
</template>

<script>
import comments from "../common/Comments.vue";
import { Toast } from "mint-ui";
export default {
  data() {
    return {
      id: this.$route.params.id, // 将URL中传递过来的id挂载到data上方便调用
      news: {},
      comments: [],
      pageIndex: 1
    };
  },
  components: {
    comments
  },
  methods: {
    getNewsDetails() {
      // 获取新闻详情
      this.$http.get("getnews?id=" + this.id).then(result => {
        if (result.status === 200 && result.body.length === 1) {
          this.news = result.body[0];
        } else Toast("新闻详情加载失败");
      });
    }
  },
  created() {
    this.getNewsDetails();
  }
};
</script>

<style lang="scss">
.details-container {
  padding: 0 4px;
  .title {
    font-size: 16px;
    text-align: center;
    margin: 15px 0;
    color: red;
  }
  .subtitle {
    font-size: 13px;
    color: #226aff;
    display: flex;
    justify-content: space-between;
  }
  .content {
    img {
      width: 100% !important;
      height: auto !important;
    }
  }
}
</style>

